package com.dev.stream;

import com.dev.stream.pojo.Person;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 戴 骥
 * @date 2021-09-05 17:00
 */
public class FilterStream {
    @Test
    public void filterStream() {
        List<Integer> list = Arrays.asList(7, 6, 9, 3, 8, 2, 1);

        List<Person> personList = new ArrayList<Person>();
        personList.add(new Person("韩梅梅", 8900, 22, "女", "武汉"));
        personList.add(new Person("李磊", 7000, 33, "男", "上海"));
        personList.add(new Person("Lucy", 7800, 44, "女", "北京"));
        personList.add(new Person("狗哥", 8200, 55, "男", "深圳"));
        personList.add(new Person("Lily", 9500, 66, "女", "深圳"));
        personList.add(new Person("Jim", 7900, 77, "男", "深圳"));

        //筛选出list大于6的
        list.stream().filter(t -> t > 6).forEach(System.out::println);
        //筛选员工中工资高于8000的人，并形成新的集合
        personList.stream().filter(t -> t.getSalary() > 8000).forEach(System.out::println);
        //返回新集合
        List<Person> personNewList =
                personList.stream().filter(t -> t.getSalary() > 8000).collect(Collectors.toList());
        System.out.println("personNewList = " + personNewList);
        //找出所有妹子
        List<Person> personBySexList =
                personList.stream().filter(t -> t.getSex().equals("女")).collect(Collectors.toList());
        System.out.println("personBySexList = " + personBySexList);
        //找出所有武汉的人
        List<Person> personListByArea =
                personList.stream().filter(t -> t.getArea().equals("武汉")).collect(Collectors.toList());
        System.out.println("personListByArea = " + personListByArea);
        //自行完成  处于天命的人
        List<Person> personListByAge =
                personList.stream().filter(t -> t.getAge() > 50).collect(Collectors.toList());
        System.out.println("personListByAge = " + personListByAge);

    }
}
